package by.gravity.grsu.shedule.fragments;

import java.util.Date;

import android.app.AlertDialog;
import android.app.Dialog;
import android.content.DialogInterface;
import android.content.DialogInterface.OnClickListener;
import android.os.Bundle;
import android.support.v4.app.DialogFragment;
import by.gravity.grsu.shedule.OnDateSelectListener;
import by.gravity.grsu.shedule.R;
import by.gravity.grsu.shedule.util.CalendarHelper;

public class SelectWeekFragment extends DialogFragment {

	private OnDateSelectListener mListener;
	
	private Date[] dates;

	public SelectWeekFragment(OnDateSelectListener listener) {
		this.mListener = listener;
		dates = CalendarHelper.getPossibleSelected();
	}

	@Override
	public Dialog onCreateDialog(Bundle savedInstanceState) {
		return new AlertDialog.Builder(getActivity()).setTitle(getString(R.string.select_week))
				.setItems(CalendarHelper.convertToFriendlyDate(dates), new OnClickListener() {

					@Override
					public void onClick(DialogInterface paramDialogInterface, int paramInt) {
						if (mListener != null) {
							mListener.onDateSelected(dates[paramInt]);
						}

					}
				}).create();
	}

}
